package com.zenithsun.news.statistics.service.impl;

import java.util.HashMap;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.syzg.common.service.impl.BaseServiceImpl;
import com.zenithsun.news.statistics.dao.StatisticsDAO;
import com.zenithsun.news.statistics.model.ColumnNewsPV;
import com.zenithsun.news.statistics.model.NewsPV;
import com.zenithsun.news.statistics.service.StatisticsService;

@Service("statisticsService")
@Transactional
public class StatisticsServiceImpl extends BaseServiceImpl<NewsPV> implements StatisticsService{
	@Autowired
	private StatisticsDAO statisticsDAO;
	
	@Override
	public List<HashMap<String, Object>> listColumnsNewsCounter()throws Exception {
		return statisticsDAO.listColumnsNewsCounter();
	}
	
	@Override
	public List<HashMap<String, Object>> listColumnsNewsPVCounter()throws Exception {
		return statisticsDAO.listColumnsNewsPVCounter();
	}
	
	@Override
	public List<HashMap<String, Object>> listNewsDailyPVCounter()throws Exception {
		return statisticsDAO.listNewsDailyPVCounter();
	}
	
	@Override
	public List<HashMap<String, Object>> listNewsMonthPVCounter()throws Exception {
		return statisticsDAO.listNewsMonthPVCounter();
	}
	
	@Override
	public List<HashMap<String, Object>> findPVCounter() throws Exception {
		// TODO Auto-generated method stub
		return statisticsDAO.findPVCounter();
	}
	
	@Override
	public List<HashMap<String, Object>> findNewsPV(NewsPV pv) throws Exception {
		// TODO Auto-generated method stub
		return statisticsDAO.findNewsPV(pv);
	}
	
	@Override
	public List<HashMap<String, Object>> findNewsPVTotal(NewsPV pv) throws Exception {
		// TODO Auto-generated method stub
		return statisticsDAO.findNewsPVTotal(pv);
	}
	
	public boolean saveNewsPV(NewsPV pv) throws Exception{
		return statisticsDAO.saveNewsPV(pv);
	}
	
	@Override
	public List<HashMap<String, Object>> findColumnPVCounter() throws Exception {
		// TODO Auto-generated method stub
		return statisticsDAO.findColumnPVCounter();
	}
	@Override
	public boolean saveColumnNewsPV(ColumnNewsPV pv) throws Exception {
		// TODO Auto-generated method stub
		return statisticsDAO.saveColumnNewsPV(pv);
	}
	
	@Override
	public List<HashMap<String, Object>> findNewsPVTotalByColumnId(ColumnNewsPV pv) throws Exception {
		// TODO Auto-generated method stub
		return statisticsDAO.findNewsPVTotalByColumnId(pv);
	}
	@Override
	public HashMap<String, String> findPVTotalGroupColumnId() throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, Object>> list = statisticsDAO.findPVTotalGroupColumnId();
		HashMap<String, String> map = new HashMap<>();
		for (HashMap<String, Object> o : list) {
			map.put("k_"+o.get("column_id").toString(), o.get("total") == null ? "0" : o.get("total").toString());
		}
		return map;
	}
}
